﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HCQ2_Model.Pay
{
    /// <summary>
    /// 提交订单请求参数
    /// </summary>
    public class SubmitOrderParams : IPayUser, IValidatableObject
    {
        /// <summary>
        /// 【必填】购买人ID
        /// </summary>
        [Required(ErrorMessage ="购买人ID不能为空")]
        public string userid { get; set; }
        /// <summary>
        /// 【必填】订单来源；pc、web、mobile、wechat
        /// </summary>
        [Required(ErrorMessage = "订单来源不能为空")]
        public string OrderSource { get; set; }
        ///// <summary>
        ///// 付款方式；1(金币)、2(微信)、3(支付宝)
        ///// </summary>
        //[Required(ErrorMessage = "付款方式不能为空")]
        //[Range(1,3 ,ErrorMessage = "付款方式值无效，必须是：1(金币)、2(微信)、3(支付宝)其中之一")]
        //public Nullable<int> PayMethod { get; set; }
        /// <summary>
        /// 【必填】购买商品ID和购买期限
        /// </summary>
        [Required(ErrorMessage = "购买商品ID和购买期限不能为空")]
        public List<PaymentAmountParamsCommodityInfo> CommodityInfos { get; set; }

        /// <summary>
        /// 下单方式：0(从购物车下单，下单成功删除购物车商品)、1(后台批量购买,不会去购物车删除)，默认值：0
        /// </summary>
        /// <remarks>
        /// 添加这个参数是因为：从购物车下单需要删除购物车商品，从后台批量购买不用，用这个参数来标识
        /// </remarks>
        [Range(0,1,ErrorMessage = "下单方式值错误，只能是：0(从购车下单)或1(后台批量购买)，默认值是：0")]
        public int SubmitType { get; set; } = 0;

        /// <summary>
        /// 商铺ID（导航树ID）
        /// </summary>
        /// <remarks>
        /// 2021-3-1，需求《VLions需求规格_度度商城_后台-20210205.docx》添加
        /// </remarks>
        public int? FolderId { get; set; }

        /// <summary>
        /// 商品分享人ID
        /// </summary>
        /// <remarks>
        /// 2021-3-12，需求《VLions需求规格_销售管理_20210119.docx》添加
        /// </remarks>
        public int? ShareUserId { get; set; }


        #region 禅道需求286添加

        /// <summary>
        /// 收货人姓名
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 收货人电话
        /// </summary>
        public string Phone { get; set; }

        /// <summary>
        /// 所在地区
        /// </summary>
        public string Area { get; set; }

        /// <summary>
        /// 详细地址
        /// </summary>
        public string Address { get; set; }

        /// <summary>
        /// 下单类别，0=普通下单（默认值），1=扫码点餐下单
        /// </summary>
        public int OrderType { get; set; }

        /// <summary>
        /// 包装类别，0=堂食，1=打包，2=外卖
        /// </summary>
        /// <remarks>
        /// 2021-11-15：增加类别2外卖，禅道需求226
        /// </remarks>
        public int? PackType { get; set; }

        /// <summary>
        /// 经度
        /// </summary>
        public Nullable<decimal> GpsX { get; set; }

        /// <summary>
        /// 纬度
        /// </summary>
        public Nullable<decimal> GpsY { get; set; }

        #endregion


        /// <summary>
        /// 参数校验
        /// </summary>
        /// <param name="validationContext"></param>
        /// <returns></returns>
        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            SubmitOrderParams param = validationContext.ObjectInstance as SubmitOrderParams;

            if (param != null)
            {
                //订单来源
                if (param.OrderSource != null && !OrderSourceEnum.pc.Equals(param.OrderSource)
                    && !OrderSourceEnum.web.Equals(param.OrderSource)
                    && !OrderSourceEnum.mobile.Equals(param.OrderSource)
                    && !OrderSourceEnum.wechat.Equals(param.OrderSource))
                {
                    yield return new ValidationResult("订单来源值无效，必须是：pc、web、mobile、wechat其中之一", new string[] { "OrderSource" });
                }
            }
        }
    }
}
